<?
/**
* <b>fileHelper</b>
*
* This class file helps out with common file handling functions and tasks.
*
* @package gravy.classes
* @class fileHelper
* @internal It's not recommended at all to modify this code.
* @author Lars Sorhus (lars@saucecode.com.au)
*/
class fileHelper{
	
	/**
	* <b>__construct</b>
	* @fn __construct
	* @return void
	*/
	public function __construct(){
	}

	/**
	* <b>formatFileSize</b>
	* 
	* Formats a file size to look pretty.
	* 
	* @fn formatFileSize
	* @param $var - [def=null]
	* @param $format - [def="a"]
	* @return string
	*/
	static function formatFileSize($var=NULL,$format="a"){
		$result="";
		$file_size=0;
		if(is_string($var)&&@file_exists($var)){
			$file_size=(int)@filesize($var);
		}elseif(if_numeric($var)){
			$file_size=(int)$var;
		}
		if($format=="a"){
			$sizes=array('B','KB','MB','GB','TB');
			if($file_size < 0){
				$result="0".$sizes[0];
			}else{
				$conversion=1024;
				$e=(int)(log($file_size,$conversion));
				$result=number_format($file_size/pow($conversion,$e),2).$sizes[$e];
			}
		}
		return($result);
	}
};
?>
